/**
 * @type {Date}
 *
 * @properties={typeid:35,uuid:"3FA82A70-F09B-4C32-A977-B0613BAC6205",variableType:93}
 */
var fechita = application.getServerTimeStamp();

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"507BA95F-156E-446F-BEC2-B412028C9D80"}
 */
function iniciar(firstShow, event) 
{
	globals.gFechaDesde=application.getServerTimeStamp();
	globals.gFechaHasta=application.getServerTimeStamp();
	globals.gFechaDesde=globals.gFechaDesde.setDate (globals.gFechaHasta.getDate() - scopes.globals.zparam_planes_dias_atras)
	
	if (firstShow)
	{
		foundset.loadAllRecords();
		databaseManager.setAutoSave(true);
		buscar();
	}
}

/**
 * @properties={typeid:24,uuid:"65DE68CE-D19E-443E-82D3-2E18E4832206"}
 * @AllowToRunInFind
 */
function buscar() 
{
	foundset.loadAllRecords();  
	if(controller.find() == false)
	{
		globals.gMensaje ='No encontró planes (find)';
		globals.DIALOGS.showInfoDialog('Planes de Fabricacion',  globals.gMensaje,  "OK") //  30/12/2013
		return false; 
	}
	
	if(globals.gFechaDesde != null && globals.gFechaHasta != null)
	{
		var d1 = globals.gFechaDesde
		d1.setHours(00);
		d1.setMinutes(00);
		d1.setSeconds(00);             
		var df1 = utils.dateFormat(d1, 'dd-MM-yyyy HH:mm:ss')
		
		var d2 = globals.gFechaHasta
		d2.setHours(23);
		d2.setMinutes(59);
		d2.setSeconds(59);
		var df2 = utils.dateFormat(d2, 'dd-MM-yyyy HH:mm:ss');
		fecha= df1+'...' + df2+'|dd-MM-yyyy HH:mm:ss';
	}
		
	var found = controller.search()
	if(found==0)
	{
		globals.gMensaje='No encontró planes en ese rango'
		globals.DIALOGS.showInfoDialog('Planes de Fabricacion',  globals.gMensaje,  "OK") //  30/12/2013
		return false;
	} 
	return true
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"65D8BEEE-127B-423B-BECC-4472EC226CC6"}
 */
function todos(event) 
{
	globals.gFechaDesde=null;
	globals.gFechahasta=null;
	if(event.getElementName() == 'todos') 
		buscar();
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"353A91C1-51F6-4F33-A9F6-0DC595062901"}
 */
function Ira_detalle(event) 
{
	//forms.planes_det.controller.loadRecords(planes_id)
	globals.mostrarForm("planes_det")
}
